package com.eaoa.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.eaoa.base.EABaseBusinessObject;
import com.stony.core.exception.RunException;
import com.stony.core.util.CoreUtils;

public class GetEmployeeaccountBO extends EABaseBusinessObject {

	private String q;

	private String r = "";

	private String projectcustomer;

	public GetEmployeeaccountBO(String q, String projectcustomer) {
		super();
		this.q = q;
		this.projectcustomer = projectcustomer;
	}

	protected void performBusinessLogic() {

		boolean f = true;

		PreparedStatement pstm = null;
		ResultSet rset = null;

		String sql = "select a.employeeno,a.employeecode,a.employeeaccount,a.employeenamecn from hr_employee a where a.islock='N' "
				+ " AND (lower( a.employeeno) LIKE '%"
				+ q
				+ "%' OR lower (a.employeecode) LIKE '%"
				+ q
				+ "%' OR lower (a.employeeaccount) LIKE '%"
				+ q
				+ "%' OR lower (a.employeenamecn) LIKE '%"
				+ q
				+ "%') ORDER BY a.employeeno";
		try {
			Connection conn = getSession().connection();

			pstm = conn.prepareStatement(sql);

			rset = pstm.executeQuery();

			while (rset.next()) {

				if (f) {
					r = rset.getString(1) + "|" + rset.getString(2) + "|"
							+ rset.getString(3) + "|"
							+ CoreUtils.formatString(rset.getString(4));
					f = false;
				} else
					r = r + "\n" + rset.getString(1) + "|" + rset.getString(2)
							+ "|" + rset.getString(3) + "|"
							+ CoreUtils.formatString(rset.getString(4));

			}

		} catch (SQLException e) {

			throw new RunException(e);

		} finally {

			try {
				if (pstm != null)
					pstm.close();
			} catch (SQLException e1) {
			}

		}

	}

	public String getR() {
		return r;
	}

}
